using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(HCHexagonController))]
public class HCHexagonControllerEditor : Editor
{
	private enum EUnit
	{
		NONE = 0,
		SQUAD,
		ASSAULT
	}
	
	private SerializedObject _object = null;
	private SerializedProperty _type = null;
	private SerializedProperty _unit = null;
	private SerializedProperty _energy = null;

	private  EUnit _unitCode = EUnit.NONE;
	
	public void OnEnable()
	{
		_object = new SerializedObject(target);
		
		_type = _object.FindProperty("_type");
		_unit = _object.FindProperty( "_unit" );
		_energy = _object.FindProperty( "_energy" );
	}
	
	public override void OnInspectorGUI()
	{
		//DrawDefaultInspector();
		_object.Update();
		
		EditorGUILayout.PropertyField( _type );
		EditorGUILayout.PropertyField( _unit );
		EditorGUILayout.PropertyField( _energy );
		
		if( GUI.changed )
		{
			HCHexagonController.EType _typeSelected = ( HCHexagonController.EType )_type.enumValueIndex;
			
			Material _mat = null;
			HCHexagonController _controler = (_object.targetObject as HCHexagonController);
			switch( _typeSelected )
			{
			case HCHexagonController.EType.EMPTY: _mat = _controler.Grid.EmptyMaterial; break;
			case HCHexagonController.EType.BLACK: _mat = _controler.Grid.BlackMaterial; break;
			case HCHexagonController.EType.WHITE: _mat = _controler.Grid.WhiteMaterial; break;
			}
			_controler.View.renderer.material = _mat;
		}
		
		GUI.changed = false;
		
		_unitCode = (EUnit)EditorGUILayout.EnumPopup("Assigned Unit:", _unitCode);
		
		if( GUI.changed )
		{
			
		}
		
		_object.ApplyModifiedProperties();
	}
}

